<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>文件上传测试</title>
</head>
<body>
<input name="file" type="file" data-allow="jpg,jpeg">
<input type="button" value="上传" onclick="upload()">
<img src="" style="display: none" id="showImg">
</body>
<script src="/js/jquery-2.1.1.min.js"></script>
<script src="/js/ajaxhook.min.js"></script>

<script src="/js/common/system.js"></script>
<script type="text/javascript">
    function upload() {
        var formData = new FormData();
        formData.append('file', $('input[name=file]')[0].files[0]);
        jQuery.support.cors = true;
        $.ajax({
            type: 'post',
            url: getApiUrl("api/upload"),
            data: formData,
            xhrFields: {
                withCredentials: true
            },
            processData: false,
            contentType: false,
            headers:{"Accept":"application/json"}
        }).success(function (result) {
            if (result.success == 1) {
                alert("上传成功");
                $("#showImg").attr("src",result.data.url);
                $("#showImg").show();
            } else {
                alert(result.msg);
            }

        });
    }
</script>
</html>